package south

import (
	//"fmt"
	"iot-base/common/cache"
	"iot-base/common/dbobj"
	"iot-base/common/logger"

	//"iot-base/common/eventtype"
	mqtt "iot-base/common/mqtt"
	//"iot-base/common/notify"
	//"iot-base/dm/common/alarm"
)

func handleState(client mqtt.IOTMQTTBroker, topic string, pCmd *mqtt.Cmd) {
	if pCmd.Body != nil {
		states, ok := pCmd.Body.(*[]dbobj.ThingState)
		if ok && states != nil {
			for _, state := range *states {
				var sstate = "offline"
				if state.State == 1 {
					sstate = "online"
				}
				cache.SetThingState(state.ThingID, sstate, state.ChangedTime)
			}
		} else {
			logger.SLog.Error("states report error get nil interface")
		}
	}
}
